

import junit.framework.TestCase;

public class TestFactoryMethod extends TestCase {
	public void testFactoryMethod() {
		WalkmanFactory wf = new SonyWalkmanFactory();
		assertEquals(1700, wf.create().getPrice());
		wf = new AppleWalkmanFactory();
		assertEquals(2200, wf.create().getPrice());
	}

	interface Walkman {
		public int getPrice();
	}

	class SonyWalkman implements Walkman {
		private int price = 1700;

		public int getPrice() {
			return this.price;
		}
	}

	class AppleWalkman implements Walkman {
		private int price = 2200;

		public int getPrice() {
			return this.price;
		}
	}

	interface WalkmanFactory {
		public Walkman create();
	}

	class SonyWalkmanFactory implements WalkmanFactory {
		public Walkman create() {
			return new SonyWalkman();
		}
	}

	class AppleWalkmanFactory implements WalkmanFactory {
		public Walkman create() {
			return new AppleWalkman();
		}
	}
}
